/**
 * 7 
 * 1,2,4
 * log(s)向上取整
 * 10
 * 1，2，4，3
 * s - 1 - 2 - 4 - 8
*/

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 2000;
int n,m;
int f[N];
struct Good
{
    int v,w;
};
int main()
{
    vector<Good> goods;
    cin >> n >> m;
    for(int i = 0;i < n;++i)
    {
        int v,w,s;
        cin >> v >> w >> s;
        for(int k = 1; k <= s;k *= 2)
        {
            s -= k;
            goods.push_back({v*k,w*k});

        }
        if(s > 0) goods.push_back({v*s,w*s}); // 剩余的插入物品组
    }

    for(auto good : goods)
        for(int j = m;j >= good.v;--j)
            f[j] = max(f[j],f[j-good.v]+good.w);
    
    cout << f[m] << endl;

    return 0;
}